using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

using PlugNT.Common;
using PlugNT.Database;
using PlugNT.Database.Common.Simple;
using PlugNT.Cms.Custom;
using PlugNT.Cms.BLL;
using PlugNT.Cms.Model;

namespace PlugNT.App.UCenter
{




    public class UcHelper 
    {






        public static string GetLeftFormat(string filepath)
        {
            string content = PlugNT.Cms.Utility.DataHelper.GetCacheFile(filepath);
            StringBuilder sb = new StringBuilder();
            foreach (AppModel app in AppPlugin.appList)
            {
                if (app.setuped)
                {
                    sb.Append(app.ucLeftmenu);
                }
            }
            return string.Format(content, sb.ToString());
        }









        public static int GetCount(int sysModelId, string tabName, string andWhere)
        {
            string sql = "select count(1) from [" + tabName + "] where 1=1 " + (sysModelId > 0 ? " and sys_model_id= " + sysModelId : "") + andWhere;
            return (int)DbHelper.GetSingle(sql);
        }











        public static DataTable GetList(int sysModelId, string tabName, int pageSize, int currPage, string andWhere, bool isReverse)
        {
            string sql = "";
            if (isReverse)
            {
                sql = Sql.GetRePagingString(pageSize, currPage, "[" + tabName + "]", "id", (sysModelId > 0 ? " and sys_model_id= " + sysModelId : "") + andWhere);
            }
            else
            {
                sql = Sql.GetPagingString(pageSize, currPage, "[" + tabName + "]", "id", (sysModelId > 0 ? " and sys_model_id= " + sysModelId : "") + andWhere);
            }
            return DbHelper.GetDataTable(sql);
        }














        public static DataTable GetList(int sysModelId, string tabName, int pageSize, int currPage, string columns, string andWhere, bool isReverse, LeftJoinInfo joininfo)
        {
            string sql = "";
            if (isReverse)
            {
                sql = Sql.GetRePagingString(pageSize, currPage, tabName, "id", columns, (sysModelId > 0 ? " and sys_model_id= " + sysModelId : "") + andWhere, joininfo);
            }
            else
            {
                sql = Sql.GetPagingString(pageSize, currPage, tabName, "id", columns, (sysModelId > 0 ? " and sys_model_id= " + sysModelId : "") + andWhere, joininfo);
            }
            return DbHelper.GetDataTable(sql);
        }



    }


}

